package site.wetsion.employ.server.controller;

import java.math.BigInteger;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import site.wetsion.employ.server.pojo.CampusNews;
import site.wetsion.employ.server.pojo.Company;
import site.wetsion.employ.server.pojo.CompanyComment;
import site.wetsion.employ.server.pojo.Domain;
import site.wetsion.employ.server.pojo.Job;
import site.wetsion.employ.server.service.CampusService;
import site.wetsion.employ.server.service.CommentRemarkService;
import site.wetsion.employ.server.service.CompanyService;
import site.wetsion.employ.server.service.JobService;
import site.wetsion.employ.server.util.Page;
/**
 * 首页相关
 * @author Wetsion
 *
 */
@Controller
public class IndexController {
	
	@Autowired
	private CompanyService companyService;
	@Autowired
	private CampusService campusService;
	@Autowired
	private JobService jobService;
	@Autowired
	private CommentRemarkService commentService;
	
	@GetMapping("index")
	public String index(Model model){
		List<Domain> domainList = companyService.showAllDomain();
		model.addAttribute("domainList", domainList);
		BigInteger id = companyService.getRecommedCompany();
		if(id.intValue()==0){
			model.addAttribute("hotCompany", null);
		}else{
			Company company = companyService.getCompanyById(id);
			model.addAttribute("hotCompany", company);
		}
		/*Page page = new Page(1, 5);
		List<Company> lastCompanyList = companyService.getLastCreateCompany(page);
		model.addAttribute("lastCompanyList", lastCompanyList);*/
		Page page = new Page(1, 5);
		List<CampusNews> annouceList = campusService.getCampusNewsListByTypeAndPage(page, 0);
		List<CampusNews> guideList = campusService.getCampusNewsListByTypeAndPage(page, 1);
		model.addAttribute("annouceList", annouceList);
		model.addAttribute("guideList", guideList);
		
		List<Job> jobList = jobService.getAllJobByPage(page);
		model.addAttribute("jobList", jobList);
		
		List<CompanyComment> commentList = commentService.getCommentsByPage(page);
		model.addAttribute("commentList", commentList);
		return "index";
	}
	
	@GetMapping("login")
	public String loginPage(){
		return "login";
	}
	
	@GetMapping("register")
	public String regPage(){
		return "register";
	}

}
